<?php
declare(strict_types=1);

namespace SixShop\Message\Controller\Api;

use think\Request;

/**
 * 系统公告API控制器
 */
class AnnouncementController extends BaseController
{
    /**
     * 获取公告列表
     */
    public function getList(Request $request)
    {
        $page = $request->param('page/d', 1);
        $limit = $request->param('limit/d', 10);
        
        // 只获取有效的公告
        $list = $this->announcementModel->getValidList($limit);
        
        return $this->success('获取成功', $list);
    }
    
    /**
     * 获取公告详情
     */
    public function getDetail(Request $request)
    {
        $id = $request->param('id/d', 0);
        if ($id <= 0) {
            return $this->error('参数错误');
        }
        
        $detail = $this->announcementModel->getDetail($id);
        if (!$detail) {
            return $this->error('公告不存在');
        }
        
        // 检查公告是否有效
        if (!$detail->isValid()) {
            return $this->error('公告已过期或未启用');
        }
        
        return $this->success('获取成功', $detail);
    }
}
